package com.akeil.flash.dialog;

import java.text.DecimalFormat;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import com.akeil.flash.pojo.Data;

import flash.Activator;

public class ChangeContentDialog extends TitleAreaDialog {
	IPreferenceStore store = Activator.getDefault().getPreferenceStore();
	//private DecimalFormat df2 = new DecimalFormat("0.00");
	private DecimalFormat df4 = new DecimalFormat("0.0000");
	private Text textSampleName;
	private Text textSampleNumber;
	private Text textPreTemperature;
	private Text textFlashTemperature;
	private Data theData = new Data();
	private int index = -1;
	
	public ChangeContentDialog(Shell parentShell) {
		super(parentShell);
		// TODO Auto-generated constructor stub
	}

	protected Control createDialogArea(Composite parent) {
		Composite composite = (Composite) super.createDialogArea(parent);
		
		Composite composite_1 = new Composite(composite, SWT.NONE);
		composite_1.setLayout(new FormLayout());
		composite_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
		
		Group group = new Group(composite_1, SWT.NONE);
		group.setText("样品基本信息");
		FormLayout fl_group = new FormLayout();
		fl_group.marginBottom = 10;
		group.setLayout(fl_group);
		FormData fd_group = new FormData();
		fd_group.top = new FormAttachment(0, 10);
		fd_group.left = new FormAttachment(0, 10);
		fd_group.right = new FormAttachment(100, -10);
		group.setLayoutData(fd_group);
		
		Label label_3 = new Label(group, SWT.NONE);
		FormData fd_label_3 = new FormData();
		fd_label_3.right = new FormAttachment(0, 84);
		fd_label_3.top = new FormAttachment(0, 13);
		fd_label_3.left = new FormAttachment(0, 23);
		label_3.setLayoutData(fd_label_3);
		label_3.setText("样品名称");
		
		Label label_4 = new Label(group, SWT.NONE);
		FormData fd_label_4 = new FormData();
		fd_label_4.right = new FormAttachment(0, 84);
		fd_label_4.top = new FormAttachment(0, 43);
		fd_label_4.left = new FormAttachment(0, 23);
		label_4.setLayoutData(fd_label_4);
		label_4.setText("样品编号");
		
		textSampleName = new Text(group, SWT.BORDER);
		FormData fd_textSampleName = new FormData();
		fd_textSampleName.right = new FormAttachment(0, 381);
		fd_textSampleName.top = new FormAttachment(0, 10);
		fd_textSampleName.left = new FormAttachment(0, 89);
		textSampleName.setLayoutData(fd_textSampleName);
		textSampleName.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				theData.setSamplename(textSampleName.getText());
			}
		});
		textSampleName.setText(theData.getSamplename());
		
		textSampleNumber = new Text(group, SWT.BORDER);
		FormData fd_textSampleNumber = new FormData();
		fd_textSampleNumber.right = new FormAttachment(0, 381);
		fd_textSampleNumber.top = new FormAttachment(0, 40);
		fd_textSampleNumber.left = new FormAttachment(0, 89);
		textSampleNumber.setLayoutData(fd_textSampleNumber);
		textSampleNumber.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				theData.setSampleno(textSampleNumber.getText());
			}
		});
		textSampleNumber.setText(theData.getSampleno());
		
		Group group_1 = new Group(composite_1, SWT.NONE);
		group_1.setText("样品物理信息");
		FormLayout fl_group_1 = new FormLayout();
		fl_group_1.marginBottom = 10;
		group_1.setLayout(fl_group_1);
		FormData fd_group_1 = new FormData();
		fd_group_1.top = new FormAttachment(group, 6);
		fd_group_1.left = new FormAttachment(0, 10);
		fd_group_1.right = new FormAttachment(100, -10);
		group_1.setLayoutData(fd_group_1);
		
		textPreTemperature = new Text(group_1, SWT.BORDER);
		FormData fd_textPreTemperature = new FormData();
		fd_textPreTemperature.right = new FormAttachment(0, 381);
		fd_textPreTemperature.top = new FormAttachment(0, 13);
		fd_textPreTemperature.left = new FormAttachment(0, 89);
		textPreTemperature.setLayoutData(fd_textPreTemperature);
		textPreTemperature.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				theData.setPretemperature(Double.parseDouble(textPreTemperature.getText()));
			}
		});
		textPreTemperature.setText(df4.format(theData.getPretemperature()));
		
		Label label_1 = new Label(group_1, SWT.NONE);
		FormData fd_label_1 = new FormData();
		fd_label_1.top = new FormAttachment(0, 16);
		fd_label_1.left = new FormAttachment(0, 21);
		label_1.setLayoutData(fd_label_1);
		label_1.setText("预置温度");
		
		textFlashTemperature = new Text(group_1, SWT.BORDER);
		FormData fd_textFlashTemperature = new FormData();
		fd_textFlashTemperature.right = new FormAttachment(0, 381);
		fd_textFlashTemperature.top = new FormAttachment(0, 42);
		fd_textFlashTemperature.left = new FormAttachment(0, 89);
		textFlashTemperature.setLayoutData(fd_textFlashTemperature);
		textFlashTemperature.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				theData.setFlashtemperature(Double.parseDouble(textFlashTemperature.getText()));
			}
		});
		textFlashTemperature.setText(df4.format(theData.getFlashtemperature()));
		
		Label label_5 = new Label(group_1, SWT.NONE);
		FormData fd_label_5 = new FormData();
		fd_label_5.top = new FormAttachment(0, 45);
		fd_label_5.left = new FormAttachment(0, 21);
		label_5.setLayoutData(fd_label_5);
		label_5.setText("闪点温度");
		
		Label lblMg = new Label(group_1, SWT.NONE);
		FormData fd_lblMg = new FormData();
		fd_lblMg.top = new FormAttachment(textPreTemperature, 3, SWT.TOP);
		fd_lblMg.left = new FormAttachment(textPreTemperature, 18);
		lblMg.setLayoutData(fd_lblMg);
		lblMg.setText("℃");
		
		Label label = new Label(group_1, SWT.NONE);
		label.setText("℃");
		FormData fd_label = new FormData();
		fd_label.bottom = new FormAttachment(textFlashTemperature, 0, SWT.BOTTOM);
		fd_label.left = new FormAttachment(lblMg, 0, SWT.LEFT);
		label.setLayoutData(fd_label);

		this.setTitle("修改样品名称、编号等信息");
		return composite;
	}
	
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText("修改测量结果");
	}
	
	
	
	@Override
	protected Point getInitialSize() {
		// TODO 自动生成的方法存根
		return new Point(460,400);
	}

	@Override
	public void setErrorMessage(String newErrorMessage) {
		// TODO Auto-generated method stub
		Button okButton = getButton(IDialogConstants.OK_ID);
        if (okButton != null) 
            okButton.setEnabled(newErrorMessage == null);
        
		super.setErrorMessage(newErrorMessage);
	}

	public Data getTheData() {
		return theData;
	}

	public void setTheData(Data theData) {
		this.theData = theData;
	}
}
